package com.yiip.mr.flowsum;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class FlowSumMapper extends Mapper<LongWritable, Text,Text, FlowBean>{

	Text text = new Text();
	FlowBean Flow = new FlowBean();
	
	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		
		//1、获取一行
		String lineString = value.toString();
		
		//2、按照\t 切割
		String[] fieldStrings = lineString.split("\t");
		
		//3、封装bean对象
		String phone = fieldStrings[1];
		text.set(phone);
		long up = Long.parseLong(fieldStrings[fieldStrings.length-3]);
		long down = Long.parseLong(fieldStrings[fieldStrings.length-2]);
		Flow.setUpFlow(up);
		Flow.setDownFlow(down);
		Flow.setSumFlow(up+down);
		
		//4、写出
		context.write(text, Flow);
	}
	
	

}
